1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, Lines, google, Cookies, Coordinates, trackMarker, |
7
|
|
|
id2alpha, alpha2id |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/// Marker |
11
|
|
|
|
12
|
|
|
function Marker(parent, id) { |
13
|
|
|
'use strict'; |
14
|
|
|
|
15
|
|
|
this.m_parent = parent; |
16
|
|
|
this.m_id = id; |
17
|
|
|
this.m_alpha = id2alpha(id); |
18
|
|
|
this.m_free = true; |
19
|
|
|
this.m_name = ""; |
20
|
|
|
this.m_marker = null; |
21
|
|
|
this.m_circle = null; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
Marker.prototype.toString = function () { |
26
|
|
|
'use strict'; |
27
|
|
|
|
28
|
|
|
return this.getAlpha() + ":" + this.getPosition().lat().toFixed(6) + ":" + this.getPosition().lng().toFixed(6) + ":" + this.getRadius() + ":" + this.getName(); |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
Marker.prototype.isFree = function () { |
33
|
|
|
'use strict'; |
34
|
|
|
|
35
|
|
|
return this.m_free; |
36
|
|
|
}; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
Marker.prototype.clear = function () { |
40
|
|
|
'use strict'; |
41
|
|
|
|
42
|
|
|
if (this.m_free) { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
this.m_free = true; |
47
|
|
|
this.m_marker.setMap(null); |
48
|
|
|
this.m_marker = null; |
49
|
|
|
this.m_circle.setMap(null); |
50
|
|
|
this.m_circle = null; |
51
|
|
|
|
52
|
|
|
$('#dyn' + this.m_id).remove(); |
53
|
|
|
|
54
|
|
|
Lines.updateLinesMarkerRemoved(this.m_id); |
55
|
|
|
this.m_parent.handleMarkerCleared(); |
56
|
|
|
}; |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
Marker.prototype.getId = function () { |
60
|
|
|
'use strict'; |
61
|
|
|
|
62
|
|
|
return this.m_id; |
63
|
|
|
}; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
Marker.prototype.getAlpha = function () { |
67
|
|
|
'use strict'; |
68
|
|
|
|
69
|
|
|
return this.m_alpha; |
70
|
|
|
}; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
Marker.prototype.getName = function () { |
74
|
|
|
'use strict'; |
75
|
|
|
|
76
|
|
|
return this.m_name; |
77
|
|
|
}; |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
Marker.prototype.setName = function (name) { |
81
|
|
|
'use strict'; |
82
|
|
|
|
83
|
|
|
this.m_name = name; |
84
|
|
|
this.update(); |
85
|
|
|
}; |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
Marker.prototype.setPosition = function (position) { |
89
|
|
|
'use strict'; |
90
|
|
|
|
91
|
|
|
this.m_marker.setPosition(position); |
92
|
|
|
this.m_circle.setCenter(position); |
93
|
|
|
this.update(); |
94
|
|
|
}; |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
Marker.prototype.getPosition = function () { |
98
|
|
|
'use strict'; |
99
|
|
|
|
100
|
|
|
return this.m_marker.getPosition(); |
101
|
|
|
}; |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
Marker.prototype.setRadius = function (radius) { |
105
|
|
|
'use strict'; |
106
|
|
|
|
107
|
|
|
this.m_circle.setRadius(radius); |
108
|
|
|
this.update(); |
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
Marker.prototype.getRadius = function () { |
113
|
|
|
'use strict'; |
114
|
|
|
|
115
|
|
|
return this.m_circle.getRadius(); |
116
|
|
|
}; |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
Marker.prototype.setNamePositionRadius = function (name, position, radius) { |
120
|
|
|
'use strict'; |
121
|
|
|
|
122
|
|
|
this.m_name = name; |
123
|
|
|
this.m_marker.setPosition(position); |
124
|
|
|
this.m_circle.setCenter(position); |
125
|
|
|
this.m_circle.setRadius(radius); |
126
|
|
|
this.update(); |
127
|
|
|
}; |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
Marker.prototype.initialize = function (map, name, position, radius) { |
131
|
|
|
'use strict'; |
132
|
|
|
|
133
|
|
|
this.m_free = false; |
134
|
|
|
this.m_name = name; |
135
|
|
|
|
136
|
|
|
// marker.png is 26x10 icons (each: 33px x 37px) |
137
|
|
|
var self = this, |
138
|
|
|
iconw = 33, |
139
|
|
|
iconh = 37, |
140
|
|
|
offsetx = (this.m_id % 26) * iconw, |
141
|
|
|
offsety = Math.floor(this.m_id / 26) * iconh, |
142
|
|
|
color = "#0090ff"; |
143
|
|
|
|
144
|
|
|
this.m_marker = new google.maps.Marker({ |
145
|
|
|
position: position, |
146
|
|
|
map: map, |
147
|
|
|
icon: new google.maps.MarkerImage( |
148
|
|
|
"img/markers.png", |
149
|
|
|
new google.maps.Size(iconw, iconh), |
150
|
|
|
new google.maps.Point(offsetx, offsety), |
151
|
|
|
new google.maps.Point(0.5 * iconw, iconh - 1) |
152
|
|
|
), |
153
|
|
|
draggable: true |
154
|
|
|
}); |
155
|
|
|
|
156
|
|
|
google.maps.event.addListener(this.m_marker, "drag", function () { self.update(); }); |
157
|
|
|
google.maps.event.addListener(this.m_marker, "dragend", function () { self.update(); }); |
158
|
|
|
|
159
|
|
|
this.m_circle = new google.maps.Circle({ |
160
|
|
|
center: position, |
161
|
|
|
map: map, |
162
|
|
|
strokeColor: color, |
163
|
|
|
strokeOpacity: 1, |
164
|
|
|
fillColor: color, |
165
|
|
|
fillOpacity: 0.25, |
166
|
|
|
strokeWeight: 1, |
167
|
|
|
radius: radius |
168
|
|
|
}); |
169
|
|
|
}; |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
Marker.prototype.update = function () { |
173
|
|
|
'use strict'; |
174
|
|
|
|
175
|
|
|
if (this.m_free) { |
176
|
|
|
return; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
var pos = this.m_marker.getPosition(), |
180
|
|
|
radius = this.m_circle.getRadius(); |
181
|
|
|
|
182
|
|
|
this.m_circle.setCenter(pos); |
183
|
|
|
|
184
|
|
|
Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name, {expires: 30}); |
185
|
|
|
$('#view_name' + this.m_alpha).html(this.m_name); |
186
|
|
|
$('#view_coordinates' + this.m_alpha).html(Coordinates.toString(pos)); |
187
|
|
|
$('#view_circle' + this.m_alpha).html(radius); |
188
|
|
|
$('#edit_name' + this.m_alpha).val(this.m_name); |
189
|
|
|
$('#edit_coordinates' + this.m_alpha).val(Coordinates.toString(pos)); |
190
|
|
|
$('#edit_circle' + this.m_alpha).val(radius); |
191
|
|
|
|
192
|
|
|
Lines.updateLinesMarkerMoved(this.m_id); |
193
|
|
|
}; |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
/// Markers |
197
|
|
|
var Markers = {}; |
198
|
|
|
Markers.m_map = null; |
199
|
|
|
Markers.m_markers = null; |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
Markers.init = function (themap) { |
203
|
|
|
'use strict'; |
204
|
|
|
|
205
|
|
|
this.m_map = themap; |
206
|
|
|
this.m_markers = new Array(26 * 10); |
207
|
|
|
|
208
|
|
|
var id; |
209
|
|
|
for (id = 0; id !== this.m_markers.length; id = id + 1) { |
210
|
|
|
this.m_markers[id] = new Marker(this, id); |
211
|
|
|
} |
212
|
|
|
}; |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
Markers.getSize = function () { |
216
|
|
|
'use strict'; |
217
|
|
|
|
218
|
|
|
return this.m_markers.length; |
219
|
|
|
}; |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
Markers.getById = function (id) { |
223
|
|
|
'use strict'; |
224
|
|
|
|
225
|
|
|
if (id < 0 || id >= this.m_markers.length) { |
226
|
|
|
return null; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
return this.m_markers[id]; |
230
|
|
|
}; |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
Markers.getUsedMarkers = function () { |
234
|
|
|
'use strict'; |
235
|
|
|
|
236
|
|
|
var count = 0; |
237
|
|
|
this.m_markers.map(function (m) { |
238
|
|
|
if (!m.isFree()) { |
239
|
|
|
count = count + 1; |
240
|
|
|
} |
241
|
|
|
}); |
242
|
|
|
return count; |
243
|
|
|
}; |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
Markers.getFreeMarkers = function () { |
247
|
|
|
'use strict'; |
248
|
|
|
|
249
|
|
|
return this.getSize() - this.getUsedMarkers(); |
250
|
|
|
}; |
251
|
|
|
|
252
|
|
|
|
253
|
|
|
Markers.getFreeId = function () { |
254
|
|
|
'use strict'; |
255
|
|
|
|
256
|
|
|
var id; |
257
|
|
|
for (id = 0; id < this.m_markers.length; id = id + 1) { |
258
|
|
|
if (this.m_markers[id].isFree()) { |
259
|
|
|
return id; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
return -1; |
263
|
|
|
}; |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
Markers.getNextUsedId = function (id) { |
267
|
|
|
'use strict'; |
268
|
|
|
|
269
|
|
|
var i; |
270
|
|
|
for (i = id + 1; i < this.m_markers.length; i = i + 1) { |
271
|
|
|
if (!this.m_markers[i].isFree()) { |
272
|
|
|
return i; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
return -1; |
276
|
|
|
}; |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
Markers.removeById = function (id) { |
280
|
|
|
'use strict'; |
281
|
|
|
|
282
|
|
|
if (id >= 0 && id < this.m_markers.length) { |
283
|
|
|
this.m_markers[id].clear(); |
284
|
|
|
} |
285
|
|
|
}; |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
Markers.deleteAll = function () { |
289
|
|
|
'use strict'; |
290
|
|
|
|
291
|
|
|
this.m_markers.map( |
292
|
|
|
function (m) { |
293
|
|
|
m.clear(); |
294
|
|
|
} |
295
|
|
|
); |
296
|
|
|
}; |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
Markers.saveMarkersList = function () { |
300
|
|
|
'use strict'; |
301
|
|
|
|
302
|
|
|
var ids = []; |
303
|
|
|
this.m_markers.map( |
304
|
|
|
function (m) { |
305
|
|
|
if (!m.isFree()) { |
306
|
|
|
ids.push(m.getId()); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
); |
310
|
|
|
Cookies.set('markers', ids.join(":"), {expires: 30}); |
311
|
|
|
}; |
312
|
|
|
|
313
|
|
|
|
314
|
|
|
Markers.toString = function () { |
315
|
|
|
'use strict'; |
316
|
|
|
|
317
|
|
|
var parts = []; |
318
|
|
|
this.m_markers.map( |
319
|
|
|
function (m) { |
320
|
|
|
if (!m.isFree()) { |
321
|
|
|
parts.push(m.toString()); |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
); |
325
|
|
|
return parts.join("*"); |
326
|
|
|
}; |
327
|
|
|
|
328
|
|
|
|
329
|
|
|
Markers.update = function () { |
330
|
|
|
'use strict'; |
331
|
|
|
|
332
|
|
|
this.m_markers.map( |
333
|
|
|
function (m) { |
334
|
|
|
m.update(); |
335
|
|
|
} |
336
|
|
|
); |
337
|
|
|
}; |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
Markers.handleMarkerCleared = function () { |
341
|
|
|
'use strict'; |
342
|
|
|
|
343
|
|
|
if (this.getUsedMarkers() === 0) { |
344
|
|
|
$('#btnmarkers2').hide(); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
this.saveMarkersList(); |
348
|
|
|
}; |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
Markers.goto = function (id) { |
352
|
|
|
'use strict'; |
353
|
|
|
|
354
|
|
|
trackMarker('goto'); |
355
|
|
|
|
356
|
|
|
var m = this.getById(id); |
357
|
|
|
if (m) { |
358
|
|
|
this.m_map.setCenter(m.getPosition()); |
359
|
|
|
} |
360
|
|
|
}; |
361
|
|
|
|
362
|
|
|
|
363
|
|
|
Markers.center = function (id) { |
364
|
|
|
'use strict'; |
365
|
|
|
|
366
|
|
|
trackMarker('center'); |
367
|
|
|
|
368
|
|
|
var m = this.getById(id); |
369
|
|
|
if (m) { |
370
|
|
|
m.setPosition(this.m_map.getCenter()); |
371
|
|
|
} |
372
|
|
|
}; |
373
|
|
|
|